<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点击变色</title>
    <style>
        .active {
            color: yellow;
            background-color: red;
        }
    </style>
</head>
<body>
<div id="app">
    <ul>
        <li v-for="(item, index) in movies" v-bind:id="index" v-on:click="liClicked(index)" v-bind:class="{active: index === currentIndex}">{{ item }}</li>
    </ul>
</div>
<script src="../../../../../js/vue.global.js"></script>
<script>
    const app = Vue.createApp({
        data() {
            return {
                movies: ["霸王别姬", "河边的错误", "三体", "教父"],
                currentIndex:null,
            }
        },
        methods: {
            liClicked(index) {
                console.log("点击了li");
                console.log(index);
                this.currentIndex = index
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>